package com.hzsai.aspect;

import com.hzsai.pojo.User;
import com.hzsai.service.Impl.UserValidatorServiceImpl;
import com.hzsai.service.UserValidatorService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class MyAspect {

    /**
     * 声明父类关系
     */
    @DeclareParents(
            value = "com.hzsai.service.Impl.UserServiceImpl",
            defaultImpl = UserValidatorServiceImpl.class)
    public UserValidatorService userValidatorService;

    /**
     * 切点
     */
    @Pointcut("execution(* com.hzsai.service.Impl.UserServiceImpl.insertUser(..))")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void before() {
        System.out.println("日志记录before...");
    }

    @After("pointCut()")
    public void after() {
        System.out.println("日志记录after...");
    }

    @AfterReturning("pointCut()")
    public void afterReturning() {
        System.out.println("日志记录afterReturning...");
    }

    @AfterThrowing("pointCut()")
    public void afterException() {
        System.out.println("日志记录afterException...");
    }

//    @Around("pointCut()")
//    public void around(ProceedingJoinPoint pjp) throws Throwable {
//        System.out.println("around before...");
//        pjp.proceed();
//        System.out.println("aound after...");
//    }

    @Before("pointCut() && args(user)")
    public void beforeParam(JoinPoint point, User user) {
        Object[] args = point.getArgs();
        System.out.println(args);
    }
}
